package com.bysj.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bysj.entity.Adv;
import com.bysj.entity.Guide;
import com.bysj.entity.News;
import com.bysj.entity.RenCai;
import com.bysj.service.AdvService;
import com.bysj.service.GuideService;
import com.bysj.service.NewsService;
import com.bysj.service.RenCaiService;
import com.bysj.service.impl.AdvServiceImpl;
import com.bysj.service.impl.GuideServiceImpl;
import com.bysj.service.impl.NewsServiceImpl;
import com.bysj.service.impl.RenCaiServiceImpl;

public class CKServlet extends HttpServlet {
	private NewsService ns=new NewsServiceImpl();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String method=request.getParameter("method");
		Integer id=Integer.parseInt(request.getParameter("id"));
		ArrayList<News> zxnlist=ns.queryZuiXinNews();
		request.getSession().setAttribute("zxnl", zxnlist);
		System.out.println(method+"-------------"+id);
		if("adv".equals(method)){
			AdvService as=new AdvServiceImpl();
			Adv ad=new Adv();
			ad.setId(id);
			Adv adv=as.queryAdv(ad);
			request.getSession().setAttribute("adv", adv);
			request.getRequestDispatcher("../ckadv.jsp").forward(request, response);
		}else if("rencai".equals(method)){
			RenCaiService rs=new RenCaiServiceImpl();
			RenCai rc=new RenCai();
			rc.setId(id);
			RenCai rencai=rs.queryRenCai(rc);
			request.getSession().setAttribute("rc", rencai);
			request.getRequestDispatcher("../ckrencai.jsp").forward(request, response);
		}else if("guide".equals(method)){
			GuideService gs=new GuideServiceImpl();
			Guide g=new Guide();
			g.setId(id);
			Guide guide=gs.queryGuide(g);
			request.getSession().setAttribute("guide", guide);
			request.getRequestDispatcher("../ckguide.jsp").forward(request, response);
		}else if("zxnews".equals(method)){
			NewsService ns=new NewsServiceImpl();
			News news=new News();
			news.setId(id);
			News zrnews=ns.queryNews(news);
			request.getSession().setAttribute("zrnews", zrnews);
			request.getRequestDispatcher("../cknews.jsp").forward(request, response);
			
		}
	}
}
